package com.xyulu.controller.system;

import com.xyulu.entity.BlogArticleEntity;
import com.xyulu.entity.common.RoleConstant;
import com.xyulu.service.BlogArticleService;
import com.xyulu.service.BlogCategoryService;
import com.xyulu.service.BlogTagService;
import com.xyulu.utils.ShiroUtil;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description 控制后台页面跳转
 * @Author luming
 * @Date 2021/3/22
 * @Version 1.0
 */
@Controller
@RequiresRoles(RoleConstant.ROOT)
@RequestMapping("/system")
public class BackController {

    @Resource
    private BlogTagService tagService;
    @Resource
    private BlogCategoryService categoryService;
    @Resource
    private BlogArticleService articleService;

    @GetMapping("/toIndex")
    public String toSystemIndex(HttpServletRequest request){
        request.setAttribute("username", ShiroUtil.getLocalUserName());
        return "system/index";
    }

    @GetMapping("/welcome")
    public String welcome(){
        return "system/welcome";
    }

    @GetMapping("/toArticleUpload")
    public String toArticleUpload(HttpServletRequest request){
        request.setAttribute("tagList",tagService.list());
        request.setAttribute("categoryList",categoryService.list());
        return "system/creation/article_upload";
    }

    @GetMapping("/toArticleEdit")
    public String toArticleEdit(Long id, HttpServletRequest request){
        BlogArticleEntity article = articleService.getById(id);
        request.setAttribute("tagList",tagService.list());
        request.setAttribute("categoryList",categoryService.list());
        request.setAttribute("article",article);
        return "system/creation/article_edit";
    }

    @GetMapping("/toArticleManager")
    public String toArticleManager(HttpServletRequest request){
        request.setAttribute("categoryList",categoryService.list());
        return "system/content/article";
    }

    @GetMapping("/toCategoryManager")
    public String toCategoryManager(){
        return "system/content/category";
    }

    @GetMapping("/toUserManager")
    public String toUserManager(){
        return "system/manage/user";
    }

}
